Add some CFG manipulation tools for IRCode#45305
Add some CFG manipulation tools for IRCode#45305tkf wants to merge 21 commits intoJuliaLang:masterfrom
Conversation
|
It looks like the tester_win32 failure is OOM #44948 |
ianatol
left a comment
There was a problem hiding this comment.
SGTM in terms of code quality, though I don't quite understand the use case. Could you explain a bit more when we would want to use allocate_new_blocks! and allocate_gotoifnot_sequence!?
|
So I think in the LICM PR I wanted to split an edge. Can you add a test for this? Goal: Also if you add comments to the test explaining what transformation is happening it would be easier to think through if we cover all test cases. |
|
I like the general direction of this. In the past I had suggested we make a stdlib for this, but I'm fine with putting it in Base for now and making code movement decisions later. In general, it would be good to have a relatively clean and stable API for IRCode. Various utilities exist in various packages, so consolidating them is a good idea. |
Co-authored-by: Ian Atol <ian.atol@juliacomputing.com>
|
IMO, this PR would make more sense if there was a second commit in it that makes more of the compiler to use these tools. |
base/compiler/ssair/ir.jl
Outdated
| Create new "singleton" basic blocks (i.e., it contains a single instruction) | ||
| before `statement_positions`. This function adds `2 * length(statement_positions)` | ||
| blocks; i.e., `length(statement_positions)` blocks for the new singleton basic | ||
| blocks and the remaining `length(statement_positions)` blocks for the basic | ||
| block containing the instructions starting at each `statement_positions`. |
There was a problem hiding this comment.
| Create new "singleton" basic blocks (i.e., it contains a single instruction) | |
| before `statement_positions`. This function adds `2 * length(statement_positions)` | |
| blocks; i.e., `length(statement_positions)` blocks for the new singleton basic | |
| blocks and the remaining `length(statement_positions)` blocks for the basic | |
| block containing the instructions starting at each `statement_positions`. | |
| Create new "singleton" basic blocks (i.e., it contains a single dummy instruction) | |
| before `statement_positions`. This function adds `2 * length(statement_positions)` | |
| instructions; i.e., `length(statement_positions)` instructions for the new singleton basic | |
| blocks and the remaining `length(statement_positions)` instructions for the basic | |
| block containing the dummy instructions starting at each `statement_positions`. |
explains better?
There was a problem hiding this comment.
I tried to pull some ideas from this. I also cleaned up the API which simplified the explanation.
|
Thanks, these tools look very useful and the code quality is great.
I'm not sure that there are such places where we manipulate CFG of |
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
@vchuravy I created a sketch for how to do LICM https://nbviewer.org/gist/tkf/d4734be24d2694a3afd669f8f50e6b0f/00_notebook.ipynb (see the last example). It's tedious to create the input IR "by hand" so I want to do this after #45306 if we are to add it to the test. @ianatol Does this also answer your question about when we would want to use these APIs? Another example was for doing the lowering of
There are single-sentence explanations in the testset labels. I also added some pseudocode for explaining the input and output IRs. |
|
Okay rebased onto ToT, and I am in the process of rewriting #36832 on top of this. |
|
@vchuravy Just checking in on the status of this PR, because it hasn't had any activity for a while. Can I close this PR, or would you like to keep it open? |
|
Please keep it open. |
This PR adds CFG manipulation function
allocate_new_blocks!and a derived functionallocate_gotoifnot_sequence!to help CFG manipulation ofIRCodes.julia/base/compiler/ssair/ir.jl
Lines 1630 to 1680 in 90133d4
julia/base/compiler/ssair/ir.jl
Lines 1937 to 1959 in 90133d4
This PR also adds a bit more somewhat automated way to wrap
Core.Compilerinterface functions asBaseinterface functions; e.g.,julia/base/compilerwrappers.jl
Lines 17 to 18 in 90133d4
Some of the manually-handled definitions in
IRShoware now handled this way. These definitions are very handy for writing tests and also playing with them in REPL. But I think this PR can be done without them if it's better to do this elsewhere.